package teach.day05;

import java.util.Map;
import java.util.TreeMap;

//统计一句话中的单词出现的次数，按照字典序输出
public class P06WordsCounter {
    public static void main(String[] args) {
        String line = "To konw everything is to  konw   nothing ";
        Map<String, Integer> M = new TreeMap<>();
//        System.out.println(line.replaceAll("[^a-zA-Z]"," "));
        String[] arr = line.trim().split("\\s+");
//        System.out.println(Arrays.toString(arr));

        //TODO
        for (String e : arr) {
            if (M.containsKey(e)) {
                int val = M.get(e);
                M.put(e, val + 1);
            } else {
                M.put(e, 1);
            }
        }
        System.out.println(M);
        System.out.println(arr.length);
        for (String word : M.keySet()) {
            System.out.println(word + ":" + M.get(word));
        }
    }
}
